﻿using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace GraphicalWebCounter
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();

            const int width = 100;
            const int height = 55;
            int visitors;
            if(Application["visitors"] == null)
            {
                visitors = 0;
            }
            else
            {
                visitors = (int)Application["visitors"] + 1;
            }
            Bitmap bitmapImage = new Bitmap(width, height);
            Graphics drawing = Graphics.FromImage(bitmapImage);
            drawing.FillRectangle(Brushes.MediumSeaGreen, 0, 0, width, height);
            Font fontType = new Font("Tahoma", 30, FontStyle.Bold);
            Brush fontColor = new SolidBrush(Color.Red);
            drawing.DrawString(visitors.ToString(), fontType, fontColor, 10, 5);

            Response.ContentType = "image/jpeg";
            bitmapImage.Save(Response.OutputStream, ImageFormat.Jpeg);
            Application["visitors"] = visitors;
        }
    }
}